package com.kelvin.paopao.module.market.wallet.recharge;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.hyphenate.easeui.utils.SpUtil;
import com.kelvin.paopao.R;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.module.market.market.market.MarketActivity;
import com.kelvin.paopao.module.market.market.order.OrderActivity;
import com.kelvin.paopao.utils.Constant;
import com.kelvin.paopao.widgets.CustomToolbar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/13.
 */

public class RechargeActivity extends BaseActivity {
    @BindView(R.id.custom_toolbar)
    CustomToolbar customToolbar;
    @BindView(R.id.webView)
    WebView webView;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_market;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        customToolbar.showBackIcon(this);
        customToolbar.inflateMenu(R.menu.menu_wallet);
        customToolbar.setMenuOnClick(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                RechargeHistoryActivity.launch(RechargeActivity.this);
                return true;
            }
        });

        WebSettings mSetting = webView.getSettings();
        mSetting.setJavaScriptEnabled(true);
        mSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.setWebViewClient(new WebViewClient() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.getUrl().toString());
                return true;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                customToolbar.setTitle(title);
            }
        });

        webView.loadUrl(Constant.USER_URL + "user/tixian/index.aspx?&userno=" + SpUtil.getLoginHuanxin_id(this));
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    public static void launch(Context context) {
        Intent intnet = new Intent(context, RechargeActivity.class);
        context.startActivity(intnet);
    }

}
